package com.example.newdemo.animator;


import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;

import androidx.core.view.ViewCompat;

import com.example.newdemo.BaseActivity;
import com.example.newdemo.R;

public class AnimatorDemoActivity extends BaseActivity {

    boolean isChange = false;


    @Override
    protected int getLayoutId() {
        return R.layout.act_animator_demo;
    }

    @Override
    protected void initView() {
        RelativeLayout rlAnimatorContent = findViewById(R.id.rl_animator_content);

        Button button = new Button(this);
        button.setText("开始");

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);

        params.leftMargin = 100;
        params.topMargin = 200;

        params.width = 300 ;
        params.height = 150 ;

        Button testButton = new Button(this);
        testButton.setText("测试");

        testButton.setLayoutParams(params);


        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //  scaleY    alpha 透明  rotation
//                ObjectAnimator animator = ObjectAnimator.ofFloat(testButton, "scaleX", 1f, 3f, 1f);
//                ObjectAnimator rotate = ObjectAnimator.ofFloat(testButton, "rotation", 0f, 360f);
//                ObjectAnimator moveIn = ObjectAnimator.ofFloat(testButton, "translationX", -500f, 0f);        // 移动
//                animator.setDuration(5000);
//                animator.start();

//                 ObjectAnimator animator = ObjectAnimator.ofFloat(testButton, "translationX", -500f, 0f);
//                animator.setDuration(5000);
//                animator.start();

                if (isChange){
                    ViewCompat.animate(testButton).scaleX(1f).scaleY(1f).translationZ(1).start();

                }else {
                    ViewCompat.animate(testButton).scaleX(1.5f).scaleY(1.5f).translationZ(1).start();
                }
                isChange = !isChange;

            }
        });






        rlAnimatorContent.addView(button);
        rlAnimatorContent.addView(testButton);

    }

    @Override
    protected void initData() {

    }


}
